//
//  XLNewUserBagView.m
//  XiangLove
//
//  Created by 宋振 on 2018/7/31.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLNewUserBagView.h"
#import "XLPersonCenterTool.h"

@interface XLNewUserBagView()

//删除界面按钮
@property (nonatomic, strong) UIButton *  deleteButton;

//领取礼包按钮
@property (nonatomic, strong) UIButton *  receiveButton;

//次数显示
@property (nonatomic, strong) UILabel *  timesLbl;

//金豆显示
@property (nonatomic, strong) UILabel *  beanLbl;

@end

@implementation XLNewUserBagView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        /**
         绘制界面显示
         */
        [self layOutCustomeView];
    }
    return self;
}

#pragma mark    -   -   -绘制界面显示-    -   -
- (void)layOutCustomeView
{
    //设置图片背景
    UIImageView *imageViewBg = [[UIImageView alloc] init];
    
    [self addSubview:imageViewBg];
    
    //添加图片
    imageViewBg.image = [[UIImage imageNamed:@"pop_bg_xrlb"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    
    [imageViewBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScale(40));
        make.right.equalTo(self.mas_right).offset(-kScale(40));
//        make.top.equalTo(self.mas_top).offset(155);
        make.height.mas_equalTo(358);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    //删除按钮
    self.deleteButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.deleteButton.frame = CGRectMake(0, 0, kScale(24), kScale(24));
    [self.deleteButton setImage:[UIImage imageNamed:@"pop_icon_chacha_n"] forState:(UIControlStateNormal)];
    [self.deleteButton addTarget:self action:@selector(deleteNewUserBag:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:self.deleteButton];
    
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageViewBg).offset(5);
        make.right.equalTo(imageViewBg).offset(-5);
        make.width.height.mas_equalTo(kScale(24));
    }];
    
    /**
     提示：标题 次数显示以及其他显示
     */
    
    //标题
    UILabel *titleLbl = [[UILabel alloc] init];
    
    //修饰
    UIColor *textColor = [UIColor colorWithRed:17/255.0 green:17/255.0 blue:17/255.0 alpha:1];
    [self setLabelShowStyleWithLabel:titleLbl fontName:kFontNamePFSemibold Size:24.0 text:@"新人大礼包" color:textColor];
    [self addSubview:titleLbl];
    
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageViewBg).offset(25);
        make.left.equalTo(imageViewBg).offset(kScale(30));
    }];
    
    //次数显示
    self.timesLbl = [[UILabel alloc] init];
    
    [self setLabelShowStyleWithLabel:self.timesLbl fontName:kFontNamePFRegular Size:32.0 text:@"3张" color:textColor];
    [self addSubview:self.timesLbl];
    
    [self.timesLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLbl.mas_bottom).offset(48);
        make.centerX.equalTo(imageViewBg);
        make.height.mas_equalTo(kScale(45));
    }];
    
    //其他
    UILabel *experienceLbl = [[UILabel alloc] init];
    
    UIColor *otherColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];
    
    [self setAttributeShowStyleWithLabel:experienceLbl fontName:kFontNamePFRegular Size:15.0 text:@"免费视频聊天卡" color:otherColor];
    [self addSubview:experienceLbl];
    
    [experienceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timesLbl.mas_bottom).offset(2);
        make.centerX.equalTo(imageViewBg);
        make.height.mas_equalTo(21);
    }];
    
    //金豆
    self.beanLbl = [[UILabel alloc] init];
    
    [self setLabelShowStyleWithLabel:self.beanLbl fontName:kFontNamePFSemibold Size:32.0 text:@"50金豆" color:textColor];
    
    [self addSubview:self.beanLbl];
    
    [self.beanLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(experienceLbl.mas_bottom).offset(13);
        make.centerX.equalTo(imageViewBg);
        make.height.mas_equalTo(45);
    }];
    
    //无门槛
    UILabel *noDoorsill = [[UILabel alloc] init];
    
//    [self setLabelShowStyleWithLabel:noDoorsill fontName:kFontNamePFRegular Size:15.0 text:@"无门槛体验" color:otherColor];
    [self setAttributeShowStyleWithLabel:noDoorsill fontName:kFontNamePFRegular Size:15.0 text:@"无门槛体验" color:otherColor];
    
    [self addSubview:noDoorsill];
    
    [noDoorsill mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.beanLbl.mas_bottom).offset(2);
        make.centerX.equalTo(imageViewBg);
        make.height.mas_equalTo(21);
    }];
    
    
    
    //领取按钮
    self.receiveButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.receiveButton.frame = CGRectMake(0, 0, kScale(160), 44);

    [self.receiveButton setAttributedTitle:[[NSAttributedString alloc] initWithString:@"确认领取" attributes:@{NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:16.0],NSForegroundColorAttributeName:RGB(17, 17, 17)}] forState:(UIControlStateNormal)];
    self.receiveButton.layer.masksToBounds = NO;
    self.receiveButton.layer.cornerRadius = 22;
    
    self.receiveButton.layer.shadowRadius = 2;
    self.receiveButton.layer.shadowOpacity = 0.7;
    self.receiveButton.layer.shadowOffset = CGSizeMake(0, 2);
    self.receiveButton.layer.shadowColor = RGB(255, 221, 0).CGColor;
    
    self.receiveButton.backgroundColor = [UIColor colorWithRed:255/255.0 green:221/255.0 blue:0/255.0 alpha:1];
    [self.receiveButton addTarget:self action:@selector(clickReceive:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:self.receiveButton];
    
    [self.receiveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(noDoorsill.mas_bottom).offset(25);
        make.centerX.equalTo(imageViewBg);
        make.size.mas_equalTo(CGSizeMake(kScale(160), 44));
    }];
    
    //设置阴影
//    CALayer *subLayer = [CALayer layer];
//    CGRect rect = self.receiveButton.layer.frame;
//    subLayer.frame = rect;
//    subLayer.shadowColor = RGB(255, 221, 0).CGColor;
//    subLayer.shadowOffset = CGSizeMake(2, 2);
//    subLayer.shadowRadius = 22;
//    subLayer.cornerRadius = 22;
//    subLayer.masksToBounds = NO;
//    subLayer.shadowOpacity = 0.7;
    
    
}

#pragma mark    -   -   -   按钮事件    -   -   -
/**
 删除新手礼包界面事件
 */
- (void)deleteNewUserBag:(UIButton *)sender
{
    NSLog(@"点击了删除按钮");
    
    [self removeFromSuperview];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(xlNewUserBagDeleteNewUserBag:)]) {
        [self.delegate xlNewUserBagDeleteNewUserBag:sender];
    }
}

/**
 领取礼包
 */
- (void)clickReceive:(UIButton *)sender
{
    NSLog(@"点击了领取礼包");
    
    [self removeFromSuperview];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(xlNewUserBagClickReceive:)]) {
        [self.delegate xlNewUserBagClickReceive:sender];
    }
}

#pragma mark    -   -   -   辅助事件    -   -   -

//label显示设置
- (void)setLabelShowStyleWithLabel:(UILabel *)label fontName:(NSString *)fontName Size:(CGFloat)size text:(NSString *)text color:(UIColor *)color
{
    //字间距
    NSDictionary *dic = @{
                          NSKernAttributeName:@3
                          };
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:dic];
    
    label.attributedText = attribute;
    label.font = [UIFont fontWithName:fontName size:size];
    label.textColor =color;
}

- (void)setAttributeShowStyleWithLabel:(UILabel *)label fontName:(NSString *)fontName Size:(CGFloat)size text:(NSString *)text color:(UIColor *)color
{
    //字间距
    NSDictionary *dic = @{
                          NSKernAttributeName:@2
                          };
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:dic];
    
    label.attributedText = attribute;
    label.font = [UIFont fontWithName:fontName size:size];
    label.textColor =color;
}

- (void)setTimeString:(NSString *)timeString
{
    _timeString = timeString;
    
    //字间距
    NSDictionary *dic = @{
                          NSKernAttributeName:@2
                          };
    
    NSString *tempString = [NSString stringWithFormat:@"%@次",timeString];
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:tempString attributes:dic];
    
    
    
    self.timesLbl.attributedText = attribute;
    
}


@end
